package net.hymnal.church;


public class SingleHymn {
	private boolean isSelected;
    private int     number;
	private String  text;
	private String  textLowCase; // using for search.
	private String  melodyFileName = null;
	private String  firstLine = null;
	
	
	SingleHymn(int _number, String _text){
		text = _text;
		textLowCase = _text.toLowerCase();
		number =_number; 
		melodyFileName = null;
		firstLine = null;
	}
	public int getNumber(){ 
		return number;	
	}
	public String getText(){
		return text;
	}	
	
	public void checkTextAndSelect(String subString) {
		String[] subStrings = subString.split(" ");
		if (subString.length() == 0) {
			subStrings = new String[1];
			subStrings[0] = subString;
		}
		int foundIndex = -1;
		for (int i = 0; i < subStrings.length; i++) {
			if (subStrings[i].length() == 0) {
				continue;
			}
			int lastFound = textLowCase.indexOf(subStrings[i]);
			if (lastFound == -1) {
				isSelected = false;
				return;
			}
			if (lastFound <= foundIndex) {
				isSelected = false;
				return;
			}
			foundIndex = lastFound + subStrings[i].length();
		}
		isSelected = true;
	}

	public boolean isSelected(){
		return isSelected;
	}

	public void setMelodyFileName(String fileName) {
		melodyFileName = fileName;
	}

	public String getMelodyFileName() {
		return melodyFileName;
	}
	
	public void setFirstLine(String firstLineArg) {
		firstLine = firstLineArg;
	}
	
	public String getFirstLine() {
		return firstLine;
	}
}
